package com.wanmait.heatingrepair.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * demo类用于创建项目时使包不为空
 * 1，避免上拉到仓库时不至于找不到此包
 * 2，用于测试
 * 3，项目后期可以删除，但切记更改项目时要及时上传和下拉
 *              --创建人：于谦涛
 *              2021.5.8
 */
@Component
public class LoginInterceptor implements HandlerInterceptor
{
    //调用控制器的功能处理方法之前执行
    //如果返回true则执行控制器的方法，返回false不执行
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("preHandle..............");
        System.out.println(request.getRequestURL());
       /* String username=request.getParameter("username");
        if(username!=null)
        {
            return true;
        }
        else {
            PrintWriter out = response.getWriter();
            out.print("not login....");
            out.close();
            return false;
        }*/
       return true;

    }

    //调用控制器的功能处理方法之后执行
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("postHandle..............");
    }
    //整个请求处理完成之后，视图渲染完毕后置调用，用于清理资源或者性能统计
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("afterCompletion..............");
    }
}
